package onlineuser

import (
	"context"
	"go-caipu/pkg/services/dto"
)

type GetOnlinePageCommand struct {
	UserName       string `form:"userName" search:"type:exact;column:user_name;table:sys_online_user" comment:"用户名"`
	BeginTime      string `form:"beginTime" search:"type:gte;column:ctime;table:sys_online_user" comment:"开始时间"`
	EndTime        string `form:"endTime" search:"type:lte;column:ctime;table:sys_online_user" comment:"结束时间"`
	dto.Pagination `search:"-"`
}

func (m *GetOnlinePageCommand) GetNeedSearch() interface{} {
	return *m
}

// OnlineCommand 请求和结果相同，暂未拆分
type OnlineCommand struct {
	Id           int    `json:"id"`
	UserId       string `json:"userId"`
	Token        string `json:"token"`
	UserName     string `json:"username"`
	NickName     string `json:"nickname"`
	ClientId     string `json:"clientId"`
	ClientType   string `json:"clientType"`
	Ip           string `json:"ip"`
	Browser      string `json:"browser"`
	Os           string `json:"os"`
	Location     string `json:"address" gorm:"size:100"`
	LoginTime    string `json:"loginTime"`
	LastActiveAt string `json:"lastActiveTime"`
}
type GetOnlineCommand struct {
	Token string
	Ip    string
	Os    string
}
type RemoveOnlineCommand struct {
	Id int64
}

type Service interface {
	GetOnlineUserPage(ctx context.Context, cmd GetOnlinePageCommand) (data []OnlineCommand, num int64, err error)
	Get(ctx context.Context, token string) (*OnlineCommand, error)
	Set(ctx context.Context, cmd OnlineCommand) error
	//Remove 用于强制退出：标记 JWT 无效
	Remove(ctx context.Context, token string) error
	IsSessionValid(ctx context.Context, token string) (bool, error)
}
